package com.rui1024.dao.impl;

import com.rui1024.dao.RegisterDao;
import com.rui1024.pojo.User;
import com.rui1024.util.Md5Util;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RegisterDaoImpl implements RegisterDao {
    public boolean insert(User user, Connection con) throws SQLException, UnsupportedEncodingException, NoSuchAlgorithmException {

        String sql = "insert into userinfo(userName,userPasswd,This,role) values(?,?,?,?)";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, user.getUserName());
        pstmt.setString(2, Md5Util.encodePwdByMd5("user.getUserPasswd()"));
        pstmt.setString(3, user.getThis());
        pstmt.setString(4, user.getRole());
        int num = pstmt.executeUpdate();
        if (num > 0) {
            return true;
        }
        return false;
    }
}
